var btn, input, o1;
var list;

function init4(item) {

    btn = document.querySelector(".btn-3")
    input = document.querySelector(".input-txt")

    btn.addEventListener("click", clickHandler);
    o1 = {
        pid: item.pid,
        ck:true,
        img: item.fangdaj1,
        txt: item.jishao,
        price: item.jiage,
        num: 0,
        total:0,
        remove:"remove"
    }
      alert("添加成功")

}


function clickHandler(e) {
    o1.num = o1.num + Number(input.value)
    o1.total=o1.num*o1.price
    var xhr = new XMLHttpRequest();
        xhr.addEventListener("load", loadHandler);
        xhr.open("POST", "http://localhost:3860/shopping");
        xhr.send(JSON.stringify(o1))
    
        function loadHandler() {
            list = JSON.parse(xhr.response)
        }
}




export default {
    init4
}
